package com.brush.brushsysapi.controller;


import com.brush.brushcommon.common.sys.service.UserService;
import com.brush.brushcommon.dto.Result;
import com.brush.brushcommon.utils.CaptchaImageUtil;
import com.brush.brushcommon.dto.sys.LoginDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;


@RestController
@Tag(name = "登录接口")
public class LoginController {


    @Resource
    private UserService userService;

    @Resource
    private RedisTemplate<String, String> redisTemplate;


    /**
     *  ShearCaptcha
     * 图片的base64编码字符串
     * redis存储
     * 接口需添加白名单放行
     * @return String
     */
    @GetMapping("/getVerifyThree")
    @Operation(summary ="生成验证码")
    public Result getVerifyThree() {
        return Result.success(CaptchaImageUtil.getVerifyThree());
    }

    /**
     * 获取手机验证码
     * @return
     */
    @Operation(summary = "获取手机验证码")
    @GetMapping("/sendCode")
    public Result sendCode(@RequestParam(name = "phone") String phone){
    return userService.sendCode(phone);
    }



    /**
     * 暂时是有后面改装
     * @param loginDto
     * @return
     */
    @Operation(summary = "账号密码登录接口")
    @PostMapping("/login")
    public Result login(@RequestBody LoginDto loginDto){
        return userService.login(loginDto);
    }


    @Operation(summary = "手机号登录接口")
    @PostMapping("/phoneLogin")
    public Result phoneLogin(@RequestBody LoginDto loginDto){

        return userService.phoneLogin(loginDto);
    }

}
